<template>
  <div>
    <h2>axios</h2>
    <button @click="getStuInfo">获取学生信息</button>
    <ul v-if="flag">
      <li>{{ msg }}</li>
    </ul>
    <ul v-else>
      <li v-for="(item, index) in info_arr" :key="index">
        {{ item.stu_id }}---{{ item.stu_name }}
      </li>
    </ul>
  </div>
</template>

<script>
export default {
  data() {
    return {
      msg: "啊对对对!",
      flag: true,
      info_arr: [],
    };
  },
  mounted() {
    console.log(this.$http);
  },
  methods: {
    getStuInfo() {
      this.$http
        .get("http://localhost:8000/search_info")
        .then((res) => {
          console.log(res.data);
          this.info_arr = res.data;
          // 更改flag的值
          this.flag = false;
        })
        .catch((err) => {
          console.log(err);
        });
    },
  }
}
</script>

<style lang="scss" scoped>

</style>